package com.qpx.goodsservice.web;


import com.qpx.common.dto.ItemDto;
import com.qpx.common.vo.ResultEntity;
import com.qpx.goodsservice.entity.TItemEnity;
import com.qpx.goodsservice.service.ItemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {

    @Autowired
    ItemService itemService;

    @RequestMapping(value = "/item/list",method = RequestMethod.GET)
    public ResultEntity getItemList(ItemDto itemDto){
        Page<TItemEnity> userList = itemService.getUserList(itemDto);
        return ResultEntity.ok(userList);
    }


    @RequestMapping(value = "/getItemById",method = RequestMethod.GET)
    public ItemDto getItemById(@RequestParam  Integer id){
        TItemEnity itemById = itemService.getItemById(id);
        ItemDto itemDto = new ItemDto();
        BeanUtils.copyProperties(itemById,itemDto);
        return itemDto;
    }
}
